package com.leyou.item.service.impl;

import com.leyou.common.enums.LyExceptionEnum;
import com.leyou.common.exceptions.LyException;
import com.leyou.common.utils.BeanHelper;
import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.mapper.TbSpecGroupMapper;
import com.leyou.item.pojo.TbSpecGroup;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.xml.ws.ServiceMode;
import java.util.List;

@Service
public class SpecServiceImpl implements SpecService {

    @Autowired
    private TbSpecGroupMapper specGroupMapper;

    @Override
    public List<SpecGroupDTO> queryGroupByCategory(Long id) {
        TbSpecGroup tbSpecGroup = new TbSpecGroup();
        tbSpecGroup.setCid(id);
        List<TbSpecGroup> groupList = specGroupMapper.select(tbSpecGroup);
        if (CollectionUtils.isEmpty(groupList)) {
            throw new LyException(LyExceptionEnum.SPEC_NOT_FOUND);
        }
        return BeanHelper.copyWithCollection(groupList,SpecGroupDTO.class);
    }
}
